//
//  guangboViewController.m
//  xiaoyiNew
//
//  Created by 讯一 on 16/12/25.
//  Copyright © 2016年 讯一. All rights reserved.
//

#import "guangboViewController.h"
#import "BroadcastGeneralViewController.h"
#import "SendSubjectViewController.h"
//宏
#define SCREEN_WIDTH    [UIScreen mainScreen].bounds.size.width
#define SCREENH_HEIGHT  [UIScreen mainScreen].bounds.size.height

@interface guangboViewController (){

    NSArray * _titles;//标题
}
@property(nonatomic, strong) UIButton * sendButton;//发表

@end

@implementation guangboViewController

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = NO;
    if (self.sendButton) {
      
        [UIView animateWithDuration:1 animations:^{
            self.sendButton.alpha = 1;
        } completion:nil];
    }
    
}
- (void)viewDidDisappear:(BOOL)animated {

    [super viewDidDisappear:animated];
    [UIView animateWithDuration:1 animations:^{
        self.sendButton.alpha = 0;
    } completion:nil];
}
- (void)viewDidLoad {
    
    [self initViewController];//设置三方界面
    [self initializeDataSource];
    [self initializeUserInterface];
    [self initializeConstraints];
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


- (void)initializeDataSource {
    //更新数据
    _titles = @[@"热门", @"校内", @"全国", @"圈子"];
    
}
- (void)initializeUserInterface {
    //初始化界面
    self.automaticallyAdjustsScrollViewInsets = NO;
    //添加发表按钮
//    [self.view addSubview:self.sendButton];
    
//    [self.scrollView addSubview:self.sendButton];
    [[UIApplication sharedApplication].keyWindow addSubview:self.sendButton];
//    self.sendButton.layer.zPosition = 0.1;
//    NSInteger indexSendBut = [[self.view subviews] indexOfObject:self.sendButton];
//    [self.view insertSubview:self.sendButton atIndex:999];
//    [self.scrollView bringSubviewToFront:self.sendButton];
}
- (void)initializeConstraints {
    //设置约束
    [self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo([UIApplication sharedApplication].keyWindow).offset(-25);
        make.bottom.equalTo([UIApplication sharedApplication].keyWindow).offset(-75);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
}
//初始化界面
- (void)initViewController {
    
    self.menuHeight = -44;//导航栏高度
    self.menuItemWidth = SCREEN_WIDTH / 5; //每个 MenuItem 的宽度
    self.menuBGColor = [UIColor whiteColor];
    
    UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 5 * 4, 22, 50, 50)];
    image.backgroundColor = [UIColor redColor];
    [self.menuView addSubview:image];
    self.menuViewStyle = WMMenuViewStyleLine;//这里设置菜单view的样式
    self.progressHeight = 2;//下划线的高度，需要WMMenuViewStyleLine样式
    self.progressColor = UIColorFromHex(0x01c7a6);//设置下划线(或者边框)颜色
    //    self.progressViewBottomSpace = 100;
    self.titleSizeSelected = 16;//设置选中文字大小
    self.titleColorSelected = UIColorFromHex(0x01c7a6);//设置选中文字颜色
    self.titleSizeNormal = 16;
    self.viewFrame = CGRectMake(0, 64, SCREEN_WIDTH, SCREENH_HEIGHT - 64);
    self.selectIndex = 0;
    self.otherGestureRecognizerSimultaneously = NO;
    self.scrollView.delegate = self;
    
}

- (UIStatusBarStyle)preferredStatusBarStyle {

    return UIStatusBarStyleLightContent;
}

#pragma mark - 点击 -
//添加
- (void)action_addClick {
  
    NSLog(@"添加");
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    SendSubjectViewController * sendVC = [[SendSubjectViewController alloc] init];
    [self.navigationController pushViewController:sendVC animated:YES];
    
}
#pragma mark - delegate -
//设置viewcontroller的个数
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    
    return _titles.count;
}

//设置对应的viewcontroller
- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    NSString * url;
    switch (index) {
        case 0:
        {
            //热门
            url = @"GetXiaoyiComments2";
        }
            break;
        case 1:
        {
            //校内
            url = @"GetXiaoyiXiaoneiComments";
        }
            break;
        case 2:
        {
            //全国
            url = @"GetXiaoyiQuanGuoComments";
        }
            break;
        case 3:
        {
            //圈子
            url = @"GetXiaoyiQuanZiComments";
        }
            break;
        default:
            break;
    }
    if (index == 1) {
        //学校
        BroadcastGeneralViewController * generalVC = [[BroadcastGeneralViewController alloc] initWithType:SchoolBarodcastType url:url];
        return generalVC;
    }else {
    
        BroadcastGeneralViewController * generalVC = [[BroadcastGeneralViewController alloc] initWithType:GeneralBarodcastType url:url];
        return generalVC;
    }
    
}

//设置每个viewcontroller的标题
- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return _titles[index];
}


#pragma mark - lazy -
- (UIButton *)sendButton {

    if (!_sendButton) {
        _sendButton = [UIButton buttonWithType:0];
        _sendButton.layer.cornerRadius = 25;
        _sendButton.layer.masksToBounds = YES;
        [_sendButton setImage:[UIImage imageNamed:@"feiji"] forState:0];
        [_sendButton addTarget:self action:@selector(action_addClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendButton;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
